package com.ygly.struts.href;

import java.sql.ResultSet;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.ygly.struts.actions.ContextAction;
import com.ygly.struts.actions.SqlAction;
import com.ygly.struts.models.Pro;
import com.ygly.struts.models.User;

public class Href5Action extends ActionSupport {

	public String execute() throws Exception {
		// TODO Auto-generated method stub
		ActionContext con = ActionContext.getContext();
		HttpServletRequest request = (HttpServletRequest )con.get(ServletActionContext.HTTP_REQUEST);
		int id=-1;
		if(request.getParameter("id")!=null){
			id = Integer.parseInt(request.getParameter("id"));
		}else{
			id = (Integer )request.getAttribute("iddd");
		}
		Map session = con.getSession();
		User user2 = (User )session.get("user");
		int stuid = -1;
		if(user2 != null){
			stuid = user2.getId();
		}
		ContextAction context = new ContextAction();
		SqlAction sql = new SqlAction();
		sql.OpenConn();
		String query = "select * from pro where Id = '"+id+"'";
		ResultSet rs = sql.executeQuery(query);
		rs.next();
		Pro pro = new Pro();
		pro.setId(rs.getInt("Id"));
		pro.setName(rs.getString("Name"));
		pro.setCom_id(rs.getInt("Com_Id"));
		pro.setCom_name(rs.getString("Com_Name"));
		pro.setIntr(rs.getString("Introduction"));
		pro.setContent(rs.getString("Content"));
		context.session("pro", pro);
		context.session("open", rs.getInt("Open"));
		query = "select * from stu_pro where Stu_Id='"+stuid+"' and Pro_Id='"+id+"' ";
		rs = sql.executeQuery(query);
		if(rs.next()){
			context.request("isattend", 1);
		}else{
			context.request("isattend", 0);
		}
		return "SUCCESS";
	}
}